Skip to content

feat(dataflow): sparse constant propagation analysis - #660

Draft
axelcool1234 wants to merge 3 commits into
opencompl:mainfrom
axelcool1234:constant-propagation
Draft

feat(dataflow): sparse constant propagation analysis#660
axelcool1234 wants to merge 3 commits into
opencompl:mainfrom
axelcool1234:constant-propagation

Conversation

@axelcool1234

@axelcool1234 axelcool1234 commented May 28, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@axelcool1234 axelcool1234 changed the title Sparse Constant Propagation + Sparse Analysis API Sparse Constant Propagation Analysis + Sparse Analysis API May 28, 2026
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 3 times, most recently from 99491a7 to 7e01138 Compare May 29, 2026 01:30
@axelcool1234
axelcool1234 marked this pull request as draft May 29, 2026 01:51
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 8 times, most recently from 316cd2b to b9f3206 Compare June 4, 2026 01:47
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 12 times, most recently from 306d05a to f25dfcb Compare June 12, 2026 06:57
@axelcool1234 axelcool1234 changed the title Sparse Constant Propagation Analysis + Sparse Analysis API feat(dataflow): sparse constant propagation analysis Jun 12, 2026
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 4 times, most recently from 856253d to 3827eb6 Compare June 13, 2026 00:31
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 2 times, most recently from 322071d to 3a9c43d Compare June 14, 2026 00:06
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch from 3a9c43d to cb599c4 Compare July 15, 2026 22:19

@axelcool1234 axelcool1234 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +127 to +192
-- TODO: Mirror MLIR's generic `op->fold` path once Veir has an operation
-- folder and fold-result representation. For now we manually handle the
-- arithmetic ops.
match (op.get! irCtx).opType with
| .arith .constant =>
if h : results.size > 0 then
-- Read the `arith.constant` and convert it into the lattice domain.
let intAttr := (op.getProperties! irCtx (.arith .constant)).value
let constant : AbstractConstant :=
.constant ⟨intAttr.type.bitwidth, Data.LLVM.Int.constant intAttr.type.bitwidth intAttr.value⟩
propagateConstant (results[0]'h) constant dfCtx irCtx
else
dfCtx
| .arith .addi =>
let flags := op.getProperties! irCtx (.arith .addi)
match foldBinaryOp? op dfCtx irCtx (fun lhs rhs =>
match Data.LLVM.Int.add lhs rhs flags.attr.nsw flags.attr.nuw with
| .val v => some (.val v)
| .poison => none) with
| some constant =>
if h : results.size > 0 then
propagateConstant (results[0]'h) constant dfCtx irCtx
else
dfCtx
| none =>
setAllToUnknownConstants results dfCtx irCtx
| .arith .muli =>
let flags := op.getProperties! irCtx (.arith .muli)
match foldBinaryOp? op dfCtx irCtx (fun lhs rhs =>
match Data.LLVM.Int.mul lhs rhs flags.attr.nsw flags.attr.nuw with
| .val v => some (.val v)
| .poison => none) with
| some constant =>
if h : results.size > 0 then
propagateConstant (results[0]'h) constant dfCtx irCtx
else
dfCtx
| none =>
setAllToUnknownConstants results dfCtx irCtx
| .arith .andi =>
match foldBinaryOp? op dfCtx irCtx (fun lhs rhs =>
match lhs, rhs with
| .val lhs', .val rhs' => some (.val (BitVec.and lhs' rhs'))
| _, _ => none) with
| some constant =>
if h : results.size > 0 then
propagateConstant (results[0]'h) constant dfCtx irCtx
else
dfCtx
| none =>
setAllToUnknownConstants results dfCtx irCtx
| .arith .subi =>
let flags := op.getProperties! irCtx (.arith .subi)
match foldBinaryOp? op dfCtx irCtx (fun lhs rhs =>
match Data.LLVM.Int.sub lhs rhs flags.attr.nsw flags.attr.nuw with
| .val v => some (.val v)
| .poison => none) with
| some constant =>
if h : results.size > 0 then
propagateConstant (results[0]'h) constant dfCtx irCtx
else
dfCtx
| none =>
setAllToUnknownConstants results dfCtx irCtx
| _ =>
setAllToUnknownConstants results dfCtx irCtx

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to replace this with #1084

@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 2 times, most recently from 1a87252 to 070b44b Compare July 16, 2026 00:20
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 9 times, most recently from 057beae to 4a0b24f Compare July 28, 2026 02:13
@axelcool1234
axelcool1234 force-pushed the constant-propagation branch 2 times, most recently from b4cbe00 to 1c10e1e Compare August 14, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant